<template>
	<custom-page>
	<view>
		<view style="padding: 0 20rpx;background-color: #fff;">
			<view style="display: flex;align-items: center; width: 100%;">
				<view style="flex: 1;margin-left: 15px;font-size: 38rpx;">头像</view>
		<u--image width="150" height="150" @click='btnphoto'  :src="userInfo.avatar" shape="circle" style="margin-right: 15px;"></u--image>
		</view>
		  <u-cell-group
		      :border="false">
		    <u-cell  title="房号" :value="detail.building_name + detail.building_num + detail.name"
		             :titleStyle="{'font-size':'38rpx'}"
		             :rightIconStyle="{'font-size':'30rpx'}"
		    ></u-cell>
		    <u-cell  title="业主" :value="userInfo.real_name" :border="false"
		             :titleStyle="{'font-size':'38rpx'}"
		             :rightIconStyle="{'font-size':'30rpx'}"
		    ></u-cell>
			<u-cell  title="手机号" :value="userInfo.tel" :border="false"
			         :titleStyle="{'font-size':'38rpx'}"
			         :rightIconStyle="{'font-size':'30rpx'}"
			></u-cell>
			<u-cell  title="性别" :value="userInfo.sex == 1? '男':'女'" :border="false"
			         :titleStyle="{'font-size':'38rpx'}"
			         :rightIconStyle="{'font-size':'30rpx'}"
			></u-cell>
			<u-cell  title="工作单位" :value="userInfo.word_unit" :border="false"
			         :titleStyle="{'font-size':'38rpx'}"
			         :rightIconStyle="{'font-size':'30rpx'}"
			></u-cell>
		  </u-cell-group>
		</view>
	</view>
	<!-- <view style="padding: 0 40rpx;margin-top: 40rpx;">
	  <u-button type="primary" size="large" @click="OK">保存</u-button>
	</view> -->
	</custom-page>
</template>

<script>
	import Api from '@/util/api.js'
	export default {
		data() {
			return {
				detail:{
					room:{}
				},
				userInfo:{}
			};
		},
		onLoad(e){
			var that = this
			that.checkUser()
			that.getUserRoom()
			if('link' in e){
				// that.img = e.link
				that.userInfo.avatar = e.link
			}
		},
		methods:{
			// 拍照
			btnphoto(){
				var that = this
				// uni.navigateTo({
				// 	// url: './messageList'
				// 	url:'../face/face?type=save'
				// })
				
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function (res) {
						console.log('临时图片路径',res)
					var formData = {
								category:'un',
								admin_id:that.userInfo.id
							}
						uni.showLoading({
							title: '上传中'
						});
						Api.getUpload(res.tempFilePaths[0],'fee_date',formData).then(res=>{
							console.log('res',res)
							that.img = res.data.detail.link
							that.userInfo.avatar = res.data.detail.link
							that.OK()
							uni.hideLoading();
						})
									  
					}
				});
			},
			// 检查用户信息
			checkUser(){
				var that  = this
				var userInfo = that.userInfo;
					if(localStorage.getItem('userInfo')){
						that.userInfo = JSON.parse(localStorage.getItem('userInfo'))
					}else{
						uni.showToast({
						    icon: 'none',   
						    duration: 3000,
						    title: "当前用户未登录"
						});
						return;
					}
			},
			getUserRoom(){
				var that = this
				var data = {
					user_id:that.userInfo.id 
				}
				Api.getUserRoom(data).then(res=>{
					console.log('获取成功',res)
					that.detail = res.data
				})
			},
			// 修改用户信息
			OK(){
				console.log(this.userInfo)
				uni.showLoading({
					title: '保存中'
				});
				Api.updateUserInfo(this.userInfo).then(res=>{
					if(res.msg == '成功'){
						localStorage.setItem('userInfo',JSON.stringify(res.data))
						uni.$u.toast(res.msg)
						uni.hideLoading();
					}else{
						uni.$u.toast(res.msg+',您还没修改')
						uni.hideLoading();
					}
				})
			}
		}
	}
</script>

<style lang="scss">

</style>
